#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
void threadFunction()
{
    std::this_thread::sleep_for(std::chrono::seconds(2));
    std::cout << "Thread finished executing." << std::endl;
}

int main()
{
    // Join
    std::thread t1(threadFunction);
    t1.join();
    std::cout << "Main thread waits for thread t1 to finish." << std::endl;

    // Detach
    std::thread t2(threadFunction);
    t2.detach();
    std::cout << "Main thread proceeds without waiting for thread t2." << std::endl;

    std::this_thread::sleep_for(std::chrono::seconds(3)); // to allow detached thread time to complete
    return 0;
}
